<template>
    <div>
        <home-head></home-head>
        <home-swiper :list="swiperList"></home-swiper>
        <home-icons :list="iconList"></home-icons>
        <home-recommend :list="recommendList"></home-recommend>
    </div>
</template>

<script>
import HomeHead from './components/Head'
import HomeSwiper from './components/Swiper'
import HomeIcons from './components/Icons'
import HomeRecommend from './components/Recommend'
import axios from 'axios'
export default{
    components: {
        HomeHead,
        HomeSwiper,
        HomeIcons,
        HomeRecommend,
    },
    data() {
        return {
            // city: '',
            swiperList: [],
            iconList: [],
            recommendList: []
        }
    },
    methods:{
        getHomeInfo() {
            axios.get('/api/index.json').then(this.getHomeInfoSucc)
        },
        getHomeInfoSucc(res) {
            res=res.data;
            if(res.ret){
                var data=res.data;
                this.swiperList=data.swiperList;
                // this.city=data.city;
                this.iconList=data.iconList;
                this.recommendList=data.recommendList;
            }
        },
        scroll(){
            this.$store.state.indexScrollTop= document.documentElement.scrollTop
        }
    },
    mounted() {
        this.getHomeInfo()
        console.log('mounted')
    },
    activated() {
        //this.getHomeInfo()
        window.addEventListener('scroll', this.scroll)
        this.$nextTick(()=>{
            document.documentElement.scrollTop=this.$store.state.indexScrollTop;
        })
    },
    deactivated(){
        window.removeEventListener('scroll', this.scroll);
    }
}
</script>

<style>

</style>
